#include "pch.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class card
{
private:
	int no;
	int money = 0;
	int consumMoney = 0;
	int saveMoney = 0;
	bool VIP = false;

public:
	card(int no) :no(no) {}
	bool isno(int no) { return this->no == no; }
	int getConsumMoney() { return this->consumMoney; }
	int getSaveMoney() { return this->saveMoney; }

	void save(int m) //缴费
	{ 
		this->money += m;
		this->saveMoney += m;
	}

	void consum(int m) //消费
	{
		if (this->VIP)
			m *= 0.9;

		this->money -= m;
		this->consumMoney += m;

		if (this->VIP == false && this->consumMoney >= 1000)
			this->VIP = true;
	}

	void display() //显示卡信息
	{
		if (this->VIP)
			cout << "----VIP会员";
		else
			cout << "----会员";
		cout << no << "----" << endl;
		cout << "余额：" << money << endl;
		cout << "缴费总额：" << saveMoney << endl;
		cout << "消费总额：" << consumMoney << endl;
		cout << "--------" << endl;
	}
};

class cardManager
{
private:
	static bool cmp1(card &r1, card &r2) { return r1.getConsumMoney() > r2.getConsumMoney(); }
	static bool cmp2(card &r1, card &r2) { return r1.getSaveMoney() > r2.getSaveMoney(); }
	static void displayAll()
	{
		for (card& c : cardManager::cardList)
			c.display();
	}

public:
	static vector<card>cardList;

	static int addCard() //新会员登记
	{
		int no = cardManager::cardList.size();
		cardManager::cardList.push_back(card(no));
		return no;
	}

	static card& findCard(int no)
	{
		for (card& c : cardManager::cardList)
		{
			if (c.isno(no))
				return c;
		}
	}

	static void removeCard(int no) //退卡
	{
		vector<card>::iterator itor = cardList.begin() + no;
		cardList.erase(itor);
	}

	//统计
	static void rank1()
	{
		sort(cardList.begin(), cardList.end(), cmp1);
		displayAll();
	}

	static void rank2()
	{
		sort(cardList.begin(), cardList.end(), cmp2);
		displayAll();
	}
};